package flexo.examples;

import flexo.graphic.Color;
import flexo.graphic.entity.particle.ParticleFactory;
import flexo.math.*;

public class Test_Graphic_MaterialSort extends Test_Graphic_Base
{
	flexo.scene.Node root;
	flexo.scene.Node gridNode;
	
	int textObj = 3; 
	
	public static void main(String[] args)
	{
		run("flexo.examples.Test_Graphic_MaterialSort");
	}
	
	public void init()
	{
		super.init();
		
		root = mainScene.addChild("root");		
		root.setPosition(new Vector(0,0,0));		
		gridNode = root.addChild("grid");
		graphic.getCamera(0).setBackgroundColor(new Color(0,0,0));
		
		// Text (MASK)
		flexo.graphic.entity.Text text = graphic.addText("fonts/Comic_Sans_MS.xml",13);
		text.setText("Hello world");
		
		flexo.graphic.Material fontMat = graphic.addMaterial("fonts/Comic_Sans_MS", "billboard");
		fontMat.getShaderParam("tex").setValue("fonts/Comic_Sans_MS.png");
		text.setMaterial("fonts/Comic_Sans_MS");
		fontMat.setBlending(flexo.graphic.Material.Blending.TRANSPARENT_MASK);
		
		for (int i = 0; i < textObj; ++i)
		{
			flexo.scene.Node textNode = root.addChild("text" + i);
			text.attachTo(textNode);
			textNode.setPosition(new Vector(0,0,-i * 1));
		}
		
		// Billboard (SOLID)
		flexo.graphic.Material matBill = graphic.addMaterial("billMat", "billboard");
		flexo.graphic.ShaderParam param = matBill.getShaderParam("tex");
		param.setValue("textures/maptexture.jpg");
		
		flexo.scene.Node billboardNode = mainScene.addChild("billboard");

		flexo.graphic.entity.Entity billboard = graphic.addQuad(1, 1);
		billboard.setMaterial("billMat");
		billboard.attachTo(billboardNode);
		billboardNode.setPosition(new Vector(-2,0,1));
		
		// Grid (SOLID)
		flexo.graphic.Material mat = graphic.addMaterial("gridMat", "textureRepeat");
		mat.setFaceCulling(false);
		param = mat.getShaderParam("tex");
		param.setValue("textures/grid.png");
		param = mat.getShaderParam("repeatU");
		param.setValue(50.0f);
		param = mat.getShaderParam("repeatV");
		param.setValue(50.0f);
		
		flexo.graphic.entity.Entity grid = graphic.addQuad(50, 50);
		grid.setMaterial("gridMat");
		grid.attachTo(gridNode);
		gridNode.setRotation(new flexo.math.Quaternion(new flexo.math.Vector(1,0,0),-90.0f));
		gridNode.setPosition(new flexo.math.Vector(0,-3,0));
		
		// Particles ADD
		flexo.graphic.entity.ParticleSystem particles = graphic.addParticleSystem(10, 2.0f);
		mat = graphic.addMaterial("particles");
		mat.getShaderParam("tex").setValue("textures/particle.jpg");
		particles.setMaterial("particles");
		particles.getMaterial().setBlending(flexo.graphic.Material.Blending.TRANSPARENT_ADD);
		particles.addAffector(ParticleFactory.getPointEmitter());
		particles.addAffector(ParticleFactory.getLinePath(new Vector(0,1,0)));
		particles.addAffector(ParticleFactory.getTransparencyModifier());
		particles.setColor(new Color(0,0,1));
		
		flexo.scene.Node particlesNode = root.addChild("particles");
		particlesNode.setPosition(new Vector(2,0,0));
		particles.attachTo(particlesNode);
		
		// Particles ALPHA
		flexo.graphic.entity.ParticleSystem particles2 = graphic.addParticleSystem(10, 2.0f);
		mat = graphic.addMaterial("particles2");
		mat.getShaderParam("tex").setValue("textures/particle.jpg");
		particles2.setMaterial("particles2");
		particles2.getMaterial().setBlending(flexo.graphic.Material.Blending.TRANSPARENT_ALPHA);
		particles2.addAffector(ParticleFactory.getPointEmitter());
		particles2.addAffector(ParticleFactory.getLinePath(new Vector(0,1,0)));
		particles2.addAffector(ParticleFactory.getTransparencyModifier());
		particles2.setColor(new Color(1,1,0));
		
		flexo.scene.Node particlesNode2 = root.addChild("particles2");
		particlesNode2.setPosition(new Vector(-2,0,0));
		particles2.attachTo(particlesNode2);
	}

	public void cleanUp()
	{
	}	

	public void update()
	{
	}
}
